package com.yanqu.road.server.cmd.activity.condition;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FireWorkProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;

import java.math.BigInteger;
import java.util.List;

@Cmd(code = Protocol.S_CROSS_CONDITION_SYNC, desc = "跨服condition同步")
public class CrossConditonSyncCmd extends AbstractCommand {

    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        FireWorkProto.CrossConditionSyncMsg reqMsg = FireWorkProto.CrossConditionSyncMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        for(FireWorkProto.CrossUpdateUserConditionMsg cMsg : reqMsg.getDataList()){
            if(cMsg.getConditionType() == eGamePlayerEventType.FireWorkHappyValue.getValue()){
                List<GamePlayer> onlinePlayers = GamePlayerMgr.getAllOnlinePlayer();
                for(GamePlayer onlinePlayer : onlinePlayers){
                    onlinePlayer.notifyListener(eGamePlayerEventType.FireWorkHappyValue.getValue(),new BigInteger(cMsg.getValue()));
                }
            }
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
